package cn.com.itg.common;

import cn.com.itg.pojo.domain.entity.ZTMM;
import cn.com.itg.pojo.domain.entity.ZTTCIDENTICAL;
import cn.com.itg.pojo.domain.vo.MatdocSendVO;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.apache.flink.api.common.state.StateTtlConfig;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.common.typeinfo.TypeInformation;

import java.io.Serializable;
import java.util.List;

public class DescriptorUtil implements Serializable {

    public static MapStateDescriptor<String, List<ZTTCIDENTICAL>> getZttZqrwerksState(){
        MapStateDescriptor<String, List<ZTTCIDENTICAL>> state = new MapStateDescriptor<>(
                "ztt_zqrwerks",
                TypeInformation.of(new TypeHint<String>() {
                }),
                TypeInformation.of(new TypeHint<List<ZTTCIDENTICAL>>() {
                })
        );
        state.enableTimeToLive(
                StateTtlConfig.newBuilder(Time.days(7))
                        .setUpdateType(StateTtlConfig.UpdateType.OnReadAndWrite)
                        .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
                        .build()
        );
        return state;
    }

    public static MapStateDescriptor<String, List<ZTTCIDENTICAL>> getZttZqrbwartState(){
        MapStateDescriptor<String, List<ZTTCIDENTICAL>> state = new MapStateDescriptor<>(
                "ztt_zqrbwart",
                TypeInformation.of(new TypeHint<String>() {
                }),
                TypeInformation.of(new TypeHint<List<ZTTCIDENTICAL>>() {
                })
        );
        state.enableTimeToLive(
                StateTtlConfig.newBuilder(Time.days(7))
                        .setUpdateType(StateTtlConfig.UpdateType.OnReadAndWrite)
                        .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
                        .build()
        );
        return state;
    }


    public static MapStateDescriptor<String, List<ZTTCIDENTICAL>> getZttDbState(){
        MapStateDescriptor<String, List<ZTTCIDENTICAL>> state = new MapStateDescriptor<>(
                "ztt_db_state",
                TypeInformation.of(new TypeHint<String>() {
                }),
                TypeInformation.of(new TypeHint<List<ZTTCIDENTICAL>>() {
                })
        );
        state.enableTimeToLive(
                StateTtlConfig.newBuilder(Time.days(7))
                        .setUpdateType(StateTtlConfig.UpdateType.OnReadAndWrite)
                        .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
                        .build()
        );
        return state;
    }

    public static MapStateDescriptor<String,List<ZTMM>> getZtmmDbState(){
        MapStateDescriptor<String, List<ZTMM>> state = new MapStateDescriptor<>(
                "ztmm_db_state",
                TypeInformation.of(new TypeHint<String>() {
                }),
                TypeInformation.of(new TypeHint<List<ZTMM>>() {
                })
        );
        state.enableTimeToLive(
                StateTtlConfig.newBuilder(Time.days(7))
                        .setUpdateType(StateTtlConfig.UpdateType.OnReadAndWrite)
                        .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
                        .build()
        );
        return state;
    }

    public static MapStateDescriptor<String,List<ZTMM>> getZtmmState(){
        MapStateDescriptor<String, List<ZTMM>> state = new MapStateDescriptor<>(
                "ztmm_state",
                TypeInformation.of(new TypeHint<String>() {
                }),
                TypeInformation.of(new TypeHint<List<ZTMM>>() {
                })
        );
        state.enableTimeToLive(
                StateTtlConfig.newBuilder(Time.days(7))
                        .setUpdateType(StateTtlConfig.UpdateType.OnCreateAndWrite)
                        .setStateVisibility(StateTtlConfig.StateVisibility.NeverReturnExpired)
                        .build()
        );
        return state;
    }
}
